package com.huirui.server.controller.mini.program;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.CarouselVo;
import com.huirui.server.pojo.vo.HomePageProductVo;
import com.huirui.server.pojo.vo.ProductBriefInfoVo;
import com.huirui.server.pojo.vo.SeckillProductVo;
import com.huirui.server.service.CarouselService;
import com.huirui.server.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/home/page")
@Slf4j
@Tag(name = "微信小程序首页", description = "微信小程序首页展示相关API`")
public class HomePageController {

    @Resource
    private CarouselService carouselService;


    @Resource
    private ProductService productService;

    @GetMapping("/carousel")
    @Operation(summary = "获取首页轮播图数据")
    public Result<List<CarouselVo>> listHomePageCarousel() {
        List<CarouselVo> list = carouselService.listHomePageCarousel();
        return Result.success(list);
    }

    @Operation(summary = "获取首页商品秒杀信息")
    @GetMapping("/seckill/product/info")
    public Result<List<SeckillProductVo>> listHomePageSeckillProduct() {
        return Result.success(null);
    }

    @GetMapping("/bestseller")
    @Operation(summary = "大家都在买的商品", description = "查询当前畅销商品列表，按销量排序")
    public Result<PageResult<ProductBriefInfoVo>> listBestseller(
            @Parameter(description = "页码，从1开始", required = true, example = "1")
            @RequestParam Long page,
            @Parameter(description = "每页条数", required = true, example = "10")
            @RequestParam Long pageSize) {
        IPage<ProductBriefInfoVo> res = productService.listBestseller(page, pageSize);
        return Result.success(PageResult.from(res));
    }

    @GetMapping("/product/{categoryId}")
    @Operation(summary = "获取首页商品列表")
    public Result<PageResult<HomePageProductVo>> listHomePageProduct(
            @PathVariable Long categoryId,
            @RequestParam Long page,
            @RequestParam Long pageSize
    ) {
        PageResult<HomePageProductVo> res = productService.listHomePageProduct(categoryId, page, pageSize);
        return Result.success(res);
    }
}
